// CallDll
package main

/*
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <string.h>
#cgo LDFLAGS: -ldl
void* openDLL(char* dllname){
	void* handle = dlopen(dllname, 1);
	return handle;
	}
void* closeDLL(void* handle){
	dlclose(handle);
	}
void* call4(void* dllHandle,char* funcname,void* p0,void* p1,void* p2,void* p3)
{
    void* handle = dllHandle;
    void*  fptr = dlsym(handle, funcname);
    void* (*func)(void*,void*,void*,void*);
    func=fptr;
    void* result=  func(p0, p1,p2,p3);
	return result;
    }
void* call8(void* dllHandle,char* funcname,void* p0,void* p1,void* p2,void* p3,void *p4, void* p5,void* p6,void* p7)
{
    void* handle = dllHandle;
    void*  fptr = dlsym(handle, funcname);
    void* (*func)(void*,void*,void*,void*);
    func=fptr;
    void* result=  func(p0, p1,p2,p3);
	return result;
    }
*/
import "C"
import (
	"unsafe"
)

func openDLL(dllName string) uintptr {
	result := C.openDLL(C.CString(dllName))
	return uintptr(result)
}
func closeDLL(handle uintptr) {
	C.closeDLL(unsafe.Pointer(handle))
}
func call4(handle uintptr, funcName string, param0 uintptr, param1 uintptr, param2 uintptr, param3 uintptr) uintptr {
	r := C.call4(unsafe.Pointer(handle), C.CString(funcName), unsafe.Pointer(param0), unsafe.Pointer(param1), unsafe.Pointer(param2), unsafe.Pointer(param3))
	return uintptr(r)
}
func call8(handle uintptr, funcName string, param0 uintptr, param1 uintptr, param2 uintptr, param3 uintptr, param4 uintptr, param5 uintptr, param6 uintptr, param7 uintptr) uintptr {
	r := C.call8(unsafe.Pointer(handle), C.CString(funcName), unsafe.Pointer(param0), unsafe.Pointer(param1), unsafe.Pointer(param2), unsafe.Pointer(param3), unsafe.Pointer(param4), unsafe.Pointer(param5), unsafe.Pointer(param6), unsafe.Pointer(param7))
	return uintptr(r)
}
